#include <Entity.h>
#include <View.h>


/********************************
/*          Public
/********************************/

    /********************************
    /*          Constructors
    /********************************/

        Entity::Entity()
        {
            m_Transform=NULL;
            m_Mesh  =NULL;
            m_image =   NULL;
        }

    /********************************
    /*          Methods
    /********************************/
		
        void Entity::Append( Entity &entity){

            if(entity.m_Transform!=NULL){
                if(m_Transform!=NULL){
                    entity.m_Transform->Parent(*m_Transform);
                }
            }
            m_Childs.push_back(&entity);
        }

        void Entity::Update()
        {

        }

        void Entity::Display()
        {
            if(m_Mesh!=NULL)
            {
                m_Transform->Update();
                m_Material->Use();
                SendUniforms();
                if(m_image!=NULL){
                    m_image->BindTexture(m_Material->IdProgram());
                }

                m_Mesh->Display();
            }
             for(int i=0; i<m_Childs.size();i++){
                 m_Childs.at(i)->Display();
             }
        }

    /********************************
    /*          Static Properties
    /********************************/

        std::vector<Entity *> Entity::Entities;

    /********************************
    /*           Static Methods
    /********************************/


        void Entity::Remove(Entity * entity)
        {

        }

        void Entity::Remove(int id)
        {

        }

        Entity & Entity::First()
        {
            return *Entities.front();
        }

        Entity & Entity::Last()
        {
            return *Entities.back();
        }

/********************************
/*          Private
/********************************/

    /********************************
    /*          Methods
    /********************************/

        void Entity::SendUniforms(){
            for(int i=0; i<m_Uniforms.size(); i++){
                m_Uniforms.at(i)->Send();

            }
        }


